package parent

import (
	"anban/controllers"
	"anban/service"
	"anban/utils"
	"fmt"
)

type FeedbackController struct {
	controllers.BaseController
}

func (c *FeedbackController) DoAdd() {
	var res *utils.ResJsonStruct
	input := c.Input()
	if len(input["content"][0]) <= 0 {
		res = utils.ResJson(0, "请输入反馈内容", "")
		c.Data["json"] = res
		c.ServeJSON()
		return
	}
	userId := c.GetSession("userId")
	input["user_id"] = []string{fmt.Sprintf("%d", userId)}
	_, err := service.AddFeedback(input)
	if err != nil {
		res = utils.ResJson(0, "反馈失败", "")
		c.Data["json"] = res
		c.ServeJSON()
		return
	}
	res = utils.ResJson(1, "反馈成功", "")
	c.Data["json"] = res
	c.ServeJSON()
}